package com.hzsai.controller;

import com.hzsai.pojo.User;
import com.hzsai.rabbitmq.RabbitMQService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * hzsai 2019/8/1
 * usage:
 **/
@Api(tags = "RabbitMQ消息队列")
@RequestMapping("/rabbitmq")
@RestController
public class RabbitMQController {

    @Autowired
    private RabbitMQService service = null;

    @ApiOperation(value = "发送String消息")
    @PostMapping("/msg")
    public Map<String, Object> sendMsg(String msg) {
        Map<String, Object> ret = new HashMap<String, Object>();
        service.sendMsg(msg);
        ret.put("message", msg);
        return ret;
    }

    @ApiOperation(value = "发送Object消息")
    @PostMapping("/object")
    public Map<String, Object> sendUser(User user) {
        Map<String, Object> ret = new HashMap<String, Object>();
        service.sendUser(user);
        ret.put("User: ", user);
        return ret;
    }
}
